package io.github.shenbinglife.springboot2.layui.admin.service.impl;

import io.github.shenbinglife.springboot2.layui.admin.dao.DictDao;
import io.github.shenbinglife.springboot2.layui.admin.entity.Dict;
import io.github.shenbinglife.springboot2.layui.common.service.impl.BaseService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Transactional
@Service
public class DictionaryService extends BaseService<Dict, DictDao> {
    public List<Dict> findByType(String type) {
        return baseDao.findByType(type);
    }

    public void deleteById(Long[] dictIds) {
        for (Long dictId : dictIds) {
            deleteById(dictId);
        }
    }

    public Page<Dict> page(String keyword, int page, Integer limit) {
        return baseDao.findByKeywordWithPagination(keyword, PageRequest.of(page, limit, Sort.by(Sort.Order.desc("updateTime"))));
    }
}
